package kg.aibek.projecteuler.p10;

public class Problem19 {
	int count = 0;

	public void solve() {
		int currLeap = 365 % 7;
		for (int i = 1901; i < 2001; i++) {
			currLeap = sundaysInYear(i, currLeap);
		}
		System.out.println(count);
	}

	private int sundaysInYear(int year, int leap) {
		int currLeap = leap;
		for (int i = 1; i < 13; i++) {
			currLeap = sundaysInMonth(year, i, currLeap);
		}
		return currLeap;
	}

	private int sundaysInMonth(int year, int month, int leap) {
		if (leap == 6) {
			count++;
		}
		int currLeap = 0;
		if (month == 2) {
			if (year % 4 == 0) {
				currLeap = (29 + leap) % 7;
			} else {
				currLeap = (28 + leap) % 7;
			}
		} else if (month == 4 || month == 6 || month == 9 || month == 11) {
			currLeap = (30 + leap) % 7;
		} else {
			currLeap = (31 + leap) % 7;
		}
		return currLeap;
	}

	public static void main(String[] args) {
		Problem19 p = new Problem19();
		p.solve();
	}
}
